<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=<?php echo $this->getGoogleApiKey(); ?>&sensor=false&libraries=places"></script>
<script src="http://www.google.com/uds/api?file=uds.js&v=1.0" type="text/javascript"></script>
<style type="text/css">
    @media print {
        .store-locator-search-box{
            display: none;		
        }
        .store-locator-content-bottom{
            display: none;		
        }	
        #store_info{
            display: none;	
        }
        .store_info{
            display: none;
        }
    }
</style>
<script type="text/javascript">
    $(function() {
        $("#store_information").tabs();
    });
</script>
<?php
/**
 * Magestore
 * 
 * NOTICE OF LICENSE
 * 
 * This source file is subject to the Magestore.com license that is
 * available through the world-wide-web at this URL:
 * http://www.magestore.com/license-agreement.html
 * 
 * DISCLAIMER
 * 
 * Do not edit or add to this file if you wish to upgrade this extension to newer
 * version in the future.
 * 
 * @category 	Magestore
 * @package 	Magestore_Storelocator
 * @copyright 	Copyright (c) 2012 Magestore (http://www.magestore.com/)
 * @license 	http://www.magestore.com/license-agreement.html
 */
/**
 * view template
 * 
 * @see Magestore_Storelocator_Block_Storelocator
 */
header_remove("Expires");
header_remove("Cache-Control");
header_remove("Pragma");
header_remove("Last-Modified");
$store = $this->getStoreById();
$countries = $this->getListCountry();
$search_config = $this->getSearchConfig();
$levleRadiusConvert = $this->getLeveRadiusConvert(); 
$levelRadius = $this->getLevelRadius();
$unit = $this->getUnitRadius();
$deaultRadius = $this->chekRadiusDefault();
?>
<div class="page-title">
    <h1><?php echo $this->getPageTitle(); ?></h1>
</div>
<div id="store_search">
<form method="Post" action="<?php echo (Mage ::getBaseUrl() . "storelocator/index/index"); ?>" name="store_search" >
    <div class="fieldset">
        
            <h2 class="legend"><?php echo $this->__('Search by Distance') ?></h2>
        <ul class="form-list">
            <li class="fields store-locator-list">                                               
                <label for="address"><?php echo $this->__('Your location') ?></label>
                <input  autocomplete="off" onkeyup="disiableRadius(this.value)" onblur="disiableRadius(this.value)" id ="address" class="input-text" name="address" type="text" value="<?php echo $this->getRequest()->getParam('address') ?>" />
                <div style="clear:both;"></div>
                <div id="countryh"></div>
            </li>
            
              <li class="fields store-locator-list">                                         
                <label for="radius"><?php echo $this->__('Radius') ?></label>
                <input disabled="disabled" value="<?php echo $this->getRequest()->getParam('radius') ?>" name="radius" id="radius" class="input-text validate-input required-entry" /><?php echo $unit; ?>
                <div style="clear:both;"></div>
            </li>
              
        </ul>
      
    </div>
    <?php if (($search_config != NULL) && (count($search_config)) && (!in_array(5, $search_config))): ?>
         <div class="fieldset">
        
            <h2 class="legend"><?php echo $this->__('Search by Area') ?></h2>
        <ul class="form-list" >
            
                <?php foreach ($search_config as $item): ?>                
                    <?php if ($item == 0): ?>                                                                                    
                    <?php elseif ($item == 1): ?>                   
                        <li class="fields store-locator-list" >                            
                            <label for="country"><?php echo $this->__('Country') ?></label>
                            <select name="country" id="country" class="validate-select" style="width:305px;"> 
                                <option value="nothing" selected><?php echo $this->__('Select Country') ?></option>
                                <?php if (count($countries)): ?>
                                    <?php foreach ($countries as $country): ?>
                                        <?php
                                        if ($this->getRequest()->getParam('country')) {
                                            $selected = '';
                                            if ($country['value'] == $this->getRequest()->getParam('country')) {
                                                $selected = 'selected';
                                            }
                                        } else {
                                            $selected = '';
                                            if ($country['value'] == $this->getDefaultCountry()) {
                                                $selected = 'selected';
                                            }
                                        }
                                        ?>
                                        <option value="<?php echo $country['value'] ?>" <?php echo $selected; ?>><?php echo $country['label'] ?></option>
                                    <?php endforeach; ?>
                                <?php endif; ?>

                            </select>
                            <div style="clear:both;"></div>
                        </li>                                
                    <?php elseif ($item == 2): ?>                               
                        <li class="fields store-locator-list">                                        
                            <label for="state"><?php echo $this->__('State/Province') ?></label>
                            <input id="state_province" class="input-text" name="state" type="text" value="<?php echo $this->getRequest()->getParam('state') ?>"/>
                            <div style="clear:both;"></div>
                        </li>                                
                    <?php elseif ($item == 3): ?>                               
                        <li class="fields store-locator-list">                                        
                            <label for="city"><?php echo $this->__('City') ?></label>
                            <input id="city" name="city" class="input-text" type="text" value="<?php echo $this->getRequest()->getParam('city') ?>"/>
                            <div style="clear:both;"></div>
                        </li>                                
                    <?php elseif ($item == 4) : ?>                               
                        <li class="fields store-locator-list">                                         
                            <label for="zipcode"><?php echo $this->__('Zip Code') ?></label>
                            <input class="input-text" id="zipcode" name="zipcode" type="text" value="<?php echo $this->getRequest()->getParam('zipcode') ?>"/>
                            <div style="clear:both;"></div>
                        </li>

                    <?php endif; ?>
                <?php endforeach; ?>
                                                           
        </ul>

         </div>
        <?php endif; ?>          
        <div class="clear"></div>
        <div style="float:right;margin-bottom:15px">
            
             <button type="button" class="button" title="reset" onclick="setLocation('<?php echo $this->getUrl('storelocator/index/index') ?>');"><span><span><?php echo $this->__('Reset') ?></span></span></button>
                    <button type="submit" class="button" title="search"><span><span><?php echo $this->__('Search') ?></span></span></button>
        </div>
        </form>  
    </div>

<?php if ($store): ?>
    <div id="store_locator_content" class="store-locator-content" style="min-height:450px; height: auto">
        <div class="store-locator-view-detail">
            <div class="store-locator-item-name"><font size="+1"><?php if ($store->getLink()): ?><a  href="<?php echo $store->getLink(); ?>" target="_blank"><?php echo $store->getName() ?></a><?php else: ?><?php echo $store->getName() ?><?php endif; ?></font>
                <a style="float:right" onclick="printstore()" href="javascript:void(0)" class="link-print" target="_blank">Print</a> 
                <br/>

            </div>
            <br>
            <label><?php echo $this->__('Address:'); ?></label>
            <span>
                <p> <?php echo $store->getData('address') . ", " . $store->getData('city') . ", " . $store->getState(); ?></p>
                <p><?php echo $store->getCountryName() . "&nbsp; &nbsp;" . $store->getZipcode(); ?></p>
            </span>
            <?php if ($store->getPhone()): ?>
                <label><?php echo $this->__('Phone:'); ?></label>
                <span>
                    <p> <?php echo $store->getPhone(); ?></p>
                </span>
            <?php endif; ?>
            <?php if ($store->getEmail()): ?>
                <label><?php echo $this->__('Email:'); ?></label>
                <span>
                    <p> <a  href="mailto:<?php echo $store->getEmail(); ?>"><?php echo $store->getEmail(); ?></a></p>
                </span>
            <?php endif; ?>

            <p style="clear: both; display: block">
                <a  href="<?php echo $store->getLink(); ?>" target="_blank"><i><?php echo $store->getLink(); ?></i></a>
            </p> 
            <div id="store_information">
                <ul>
                    <li><a href="#tabs-1"><?php echo $this->__('Store Information'); ?></a></li>
                    <li><a href="#tabs-2"><?php echo $this->__('Directions'); ?></a></li> 
                </ul>
                <div id="tabs-1" style="overflow: hidden;">
                    <div id="open_hour">
                        <h2 class="open_hour_title"><?php echo $this->__('Opening hours'); ?></h2>

                        <ul>   
                            <li style="padding:0 0 0 10px">
                                <div style="width:48%; float:left">
                                    <?php echo $this->__('Sunday') ?>
                                </div>
                                <div style="width:48%; float:left">
                                    
                                    <?php if (($store->getSundayOpen() != null && $store->getSundayOpen() != $store->getSundayClose()) && $store->getSundayStatus() == 1): ?>
                                        <?php echo date("g:i A", strtotime($store->getSundayOpen())) . ' - ' . date("g:i A", strtotime($store->getSundayClose())) ?>
                                    <?php elseif ($store->getSundayStatus() == 1 && ($store->getSundayOpen() == $store->getSundayClose())):?>
                                        <?php echo $this->__('Open'); ?>
                                    <?php else: ?>
                                        <?php echo $this->__('Closed'); ?>
                                    <?php endif; ?>
                                </div>
                            </li>
                            <li style="padding:0 0 0 10px">
                                <div style="width:48%; float:left">
                                    <?php echo $this->__('Monday') ?>
                                </div>
                                <div style="width:48%; float:left">
                                    <?php if (($store->getMondayOpen() != null && $store->getMondayOpen() != $store->getMondayClose()) && $store->getMondayStatus() == 1): ?>
                                        <?php echo date("g:i A", strtotime($store->getMondayOpen())) . ' - ' . date("g:i A", strtotime($store->getMondayClose())) ?>
                                    <?php elseif ($store->getMondayStatus() == 1 && ($store->getMondayOpen() == $store->getMondayClose())):?>
                                        <?php echo $this->__('Open'); ?>
                                    <?php else: ?>
                                        <?php echo $this->__('Closed'); ?>
                                    <?php endif; ?>
                                </div>
                            </li>
                            <li style="padding:0 0 0 10px">
                                <div style="width:48%; float:left">
                                    <?php echo $this->__('Tuesday') ?>
                                </div>
                                <div style="width:48%; float:left">
                                    <?php if (($store->getTuesdayOpen() != null && $store->getTuesdayOpen() != $store->getTuesdayClose()) && $store->getTuesdayStatus() == 1): ?>
                                        <?php echo date("g:i A", strtotime($store->getTuesdayOpen())) . ' - ' . date("g:i A", strtotime($store->getTuesdayClose())) ?>
                                    <?php elseif ($store->getTuesdayStatus() == 1 && ($store->getTuesdayOpen() == $store->getTuesdayClose())):?>
                                        <?php echo $this->__('Open'); ?>
                                    <?php else: ?>
                                        <?php echo $this->__('Closed'); ?>
                                    <?php endif; ?>
                                </div>
                            </li>
                            <li style="padding:0 0 0 10px">
                                <div style="width:48%; float:left">
                                    <?php echo $this->__('Wednesday') ?>
                                </div>
                                <div style="width:48%; float:left">
                                    <?php if (($store->getWednesdayOpen() != null && $store->getWednesdayOpen() != $store->getWednesdayClose()) && $store->getWednesdayStatus() == 1): ?>
                                        <?php echo date("g:i A", strtotime($store->getWednesdayOpen())) . ' - ' . date("g:i A", strtotime($store->getWednesdayClose())) ?>
                                    <?php elseif ($store->getWednesdayStatus() == 1 && ($store->getWednesdayOpen() == $store->getWednesdayClose())):?>
                                        <?php echo $this->__('Open'); ?>
                                    <?php else: ?>
                                        <?php echo $this->__('Closed'); ?>
                                    <?php endif; ?>
                                </div>
                            </li>
                            <li style="padding:0 0 0 10px">
                                <div style="width:48%; float:left">
                                    <?php echo $this->__('Thursday') ?>
                                </div>
                                <div style="width:48%; float:left">
                                    <?php if (($store->getThursdayOpen() != null && $store->getThursdayOpen() != $store->getThursdayClose()) && $store->getThursdayStatus() == 1): ?>
                                        <?php echo date("g:i A", strtotime($store->getThursdayOpen())) . ' - ' . date("g:i A", strtotime($store->getThursdayClose())) ?>
                                    <?php elseif ($store->getThursdayStatus() == 1 && ($store->getThursdayOpen() == $store->getThursdayClose())):?>
                                        <?php echo $this->__('Open'); ?>
                                    <?php else: ?>
                                        <?php echo $this->__('Closed'); ?>
                                    <?php endif; ?>
                                </div>
                            </li>
                            <li style="padding:0 0 0 10px">
                                <div style="width:48%; float:left">
                                    <?php echo $this->__('Friday') ?>
                                </div>
                                <div style="width:48%; float:left">
                                    <?php if (($store->getFridayOpen() != null && $store->getFridayOpen() != $store->getFridayClose()) && $store->getFridayStatus() == 1): ?>
                                        <?php echo date("g:i A", strtotime($store->getFridayOpen())) . ' - ' . date("g:i A", strtotime($store->getFridayClose())) ?>
                                    <?php elseif ($store->getFridayStatus() == 1 && ($store->getFridayOpen() == $store->getFridayClose())):?>
                                        <?php echo $this->__('Open'); ?>
                                    <?php else: ?>
                                        <?php echo $this->__('Closed'); ?>
                                    <?php endif; ?>
                                </div>
                            </li>
                            <li style="padding:0 0 0 10px">
                                <div style="width:48%; float:left">
                                    <?php echo $this->__('Saturday') ?>
                                </div>
                                <div style="width:48%; float:left">
                                    <?php if (($store->getSaturdayOpen() != null && $store->getSaturdayOpen() != $store->getSaturdayClose()) && $store->getSaturdayStatus() == 1): ?>
                                        <?php echo date("g:i A", strtotime($store->getSaturdayOpen())) . ' - ' . date("g:i A", strtotime($store->getSaturdayClose())) ?>
                                    <?php elseif ($store->getSaturdayStatus() == 1 && ($store->getSaturdayOpen() == $store->getSaturdayClose())):?>
                                        <?php echo $this->__('Open'); ?>
                                    <?php else: ?>
                                        <?php echo $this->__('Closed'); ?>
                                    <?php endif; ?>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <?php $spencialDays = Mage::helper('storelocator')->getSpecialDays($store->getId()); ?>
                    <?php if (count($spencialDays)): ?>
                        <div id="open_hour">
                            <h2 class="open_hour_title"><?php echo $this->__('Special Days'); ?></h2>

                            <ul>   
                                <?php foreach ($spencialDays as $spencialDay): ?>

                                    <li style="padding:0 0 0 10px">
                                        <div style="width:48%; float:left">
                                            <?php echo date_format(date_create($spencialDay['date']), 'l jS F'); ?>
                                        </div>
                                        <div style="width:48%; float:left">
                                            <?php if ($spencialDay['time_open'] != null && $spencialDay['time_open'] != $spencialDay['time_close']): ?>
                                                <?php echo date("g:i A", strtotime($spencialDay['time_open'])) . ' - ' . date("g:i A", strtotime($spencialDay['time_close'])) ?>
                                            <?php else: ?>
                                                <?php echo $this->__('Closed'); ?>
                                            <?php endif; ?>                                        
                                        </div>
                                    </li>
                                <?php endforeach; ?>                            
                            </ul>
                        </div>
                    <?php endif; ?>
                    <?php $holidays = Mage::helper('storelocator')->getHolidayDays($store->getId()); ?>
                    <?php if (count($holidays)): ?>
                        <div id="open_hour">
                            <h2 class="open_hour_title"><?php echo $this->__('Holidays'); ?></h2>

                            <ul> 
                                <?php foreach ($holidays as $holiday): ?>
                                    <li style="padding:0 0 0 10px">
                                        <div style="width:48%; float:left">
                                            <?php echo date_format(date_create($holiday['date']), 'l jS F'); ?>
                                        </div>
                                        <div style="width:48%; float:left">
                                            <?php echo $this->__('Closed'); ?>
                                        </div>
                                    </li>
                                <?php endforeach; ?>
                            </ul>
                        </div>
                    <?php endif; ?>
                </div>
                <div id="tabs-2">
                    <div class="directions-type">
                        <ul id="travel-modes">
                            <li class="driving">
                                <input id="driving-rad" type="radio" name="travelMode" value="DRIVING" checked="">
                                <label for="driving-rad" title="Driving"><?php echo $this->__('Driving') ?></label>
                            </li>
                            <li class="transit">
                                <input id="transit-rad" type="radio" name="travelMode" value="TRANSIT">
                                <label for="transit-rad" title="Transit"><?php echo $this->__('Transit') ?></label>
                            </li>
                            <li class="walking">
                                <input id="walking-rad" type="radio" name="travelMode" value="WALKING">
                                <label for="walking-rad" title="Walking"><?php echo $this->__('Walking') ?></label>
                            </li>
                            <!--
                            <li class="bicycling">
                                <input id="bicycling-rad" type="radio" name="travelMode" value="BICYCLING">
                                <label for="bicycling-rad" title="Bicycling">Bicycling</label>
                            </li>
                            -->
                        </ul>
                    </div>
                    <div class="directions-input">
                        <label for="origin">A</label>
                        <input type="text" id="originA" name="origin" placeholder="<?php echo $this->__('Enter a location') ?>" autocomplete="off">
                        <p class="error">
                        </p>
                    </div>
                    <div class="directions-input">
                        <label for="origin">B</label>
                        <input readonly="true" type="text" id="originB" name="origin" placeholder="<?php echo $this->__('Enter a location') ?>" autocomplete="off" value="<?php if ($store->getData('address')) echo $store->getData('address') . ', '; ?><?php if ($store->getData('city')) echo $store->getData('city') . ', '; ?><?php if ($store->getCountry()) echo Mage::app()->getLocale()->getCountryTranslation($store->getCountry()) . ', '; ?>">
                        <p class="error">
                        </p>
                    </div>
                    <div class="swap-locations-wrapper">
                        <button type="button" onclick="changeaddress()" id="swap-locations" title="<?php echo $this->__('Swap locations A-B') ?>"><?php echo $this->__('Swap locations A-B') ?></button>
                    </div>
                    <div class="get_direction">
                        <button type="button" onclick="getdirection()" id="get_direction" title="<?php echo $this->__('Get Directions') ?>"><?php echo $this->__('Get Directions') ?></button>
                    </div>
                    <!-- direction -->

                    <div id="directions-panel">
                    </div>
                </div>
            </div> 
        </div>
        <div class="store-locator-map" style="width: 58%;height:400px" id="map">
        </div>
        <div style="width: 58%; float:left;padding: 20px 0 0 15px;">
            <?php if ($store->getDescription()): ?>
                <label style="font-weight: bold"><?php echo $this->__('Description:'); ?></label>
                <span id="description">
                    <?php echo $store->getDescription(); ?>
                </span>
            <?php endif; ?>
        </div>
        <script type="text/javascript">
            //<![CDATA[

            var myLatlng = new google.maps.LatLng(-34.397, 150.644);
            var myOptions = {
                zoom: 8,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }
            map = new google.maps.Map(document.getElementById("map"), myOptions);
            var bounds = new google.maps.LatLngBounds();
            var setLat = <?php echo $store->getLatitude() ?>;
            var setLon = <?php echo $store->getLongtitude() ?>;
            var storeId = <?php echo $store->getStorelocatorId(); ?>;
            var zoomLevel = <?php echo $store->getZoomLevel(); ?>;
            var store_info = '<div id="store_info" class="store_info" style="width: 200px"><?php echo $store->getData('address') . ", " . $store->getData('city') . ", " . $store->getState(); ?><br/></div>' +
                    '<div>' +
                    '<?php echo $store->getCountryName() . "&nbsp; &nbsp;" . $store->getZipcode(); ?>' +
                    '<br/></div>' +
                    '<div><?php echo $store->getPhone(); ?><br/></div>' +
                    '<div>' +
                    ' <a href="<?php echo $store->getLink(); ?>" style="float:right" target="_blank"><i><?php echo $this->cutLink($store->getLink()); ?></i></a>' +
                    '</div>';
            marker_point = new google.maps.LatLng(setLat, setLon);
            bounds.extend(marker_point);
            var infoWindow = new google.maps.InfoWindow();
            placeMarker(setLat, setLon, store_info, storeId, zoomLevel);


            map.fitBounds(bounds);
            map.setCenter(bounds.getCenter());
            function placeMarker(setLat, setLon, store_info, storeId) {
                var message = "geotagged geo:lat=" + setLat + " geo:lon=" + setLon + " ";
                var messageRoboGEO = setLat + ";" + setLon + "";
                var point = new google.maps.LatLng(setLat, setLon);
    <?php if ($store->getImageIcon()) { ?>
                    var image = '<?php echo $this->getImageIconByStore($store->getId(), $store->getImageIcon()); ?>';
    <?php } else { ?>
                    var image = null;
    <?php } ?>
                if (image) {
                    var marker = new google.maps.Marker({
                        position: point,
                        map: map,
                        icon: image

                    });
                }
                else {
                    var marker = new google.maps.Marker({
                        position: point,
                        map: map
                    });
                }
                google.maps.event.addListener(map, 'click', function(event) {
                    infoWindow.setContent(store_info);
                    infoWindow.setPosition(point);
                    infoWindow.open(map);

                });


                infoWindow.setContent(store_info);
                infoWindow.setPosition(point);
                infoWindow.open(map);
                if (zoomLevel != 0) {
                    map.setZoom(zoomLevel);
                }

            }

            //]]>
        </script> 
        <div class="clear" >
        </div>                       
    </div>
    <div class="store-locator-content-bottom" style="height:auto; padding: 7px 0 10px 0;">
        <?php $images = $this->getImagebyStore($store->getId()); ?>
        <?php if (count($images)): ?>
            <div class="store-locator-column-left" style="width:auto; padding-left:0px; ">   
                <span class="store-locator-title"><?php echo $this->__('Images of ' . $store->getName()); ?></span>
                <div class="locator-main-outer">
                    <p class ="locator-image-main">
                        <?php $image_big = Mage::helper('storelocator')->getBigImagebyStore($store->getId()); ?>
                        <a class="magestore-map-image" title="" href="javascript:void(0)">
                            <img id="image" src="<?php echo $image_big ?>" width="350px" hieght="253px">
                        </a>

                    </p>
                    <div class="more-views">
                        <h2>More Views</h2>
                        <ul>
                            <?php foreach ($images as $item): ?>
                                <li>
                                    <a class="locator-image-small" title=""  href="javascript:void(0)">
                                        <img onclick="changeImage(this)" width="57" height="56" alt="" src="<?php echo $item; ?>">
                                    </a>
                                </li>
                            <?php endforeach; ?>
                        </ul>
                    </div>
                </div>        
            </div>
        <?php endif; ?>
        <div class="store-locator-column-right" style="width: 500px ">
            <?php if ($this->isFbCommentEnable()): ?>
                <span class="store-locator-title"><?php echo $this->__('Comments'); ?></span>
                <div id="fb-root"></div>
                <script>(function(d, s, id) {
                        var js, fjs = d.getElementsByTagName(s)[0];
                        if (d.getElementById(id))
                            return;
                        js = d.createElement(s);
                        js.id = id;
                        js.src = "//connect.facebook.net/<?php echo $this->getLanguage() ?>/all.js#xfbml=1&appId=<?php echo $this->getFacebookApiKey(); ?>";
                        fjs.parentNode.insertBefore(js, fjs);
                    }(document, 'script', 'facebook-jssdk'));</script>
                <div class="fb-comments" data-href="<?php echo Mage::helper('core/url')->getCurrentUrl(); ?>" data-width="500" data-num-posts="10"></div>

            <?php endif; ?>
        </div>
        <div class="clear"></div>
    </div>
<?php else: ?>
    <?php echo $this->__('Store Not Found!'); ?>
<?php endif; ?>

<script type="text/javascript">

    function changeaddress() {
        var temp = document.getElementById('originA').value;
        document.getElementById('originA').value = document.getElementById('originB').value;
        document.getElementById('originB').value = temp;
        if (document.getElementById('originB').readOnly) {
            document.getElementById('originB').readOnly = false;
            document.getElementById('originA').readOnly = true;
            var inputB = (document.getElementById('originB'));
            var autocompleteB = new google.maps.places.Autocomplete(inputB);
            autocompleteB.bindTo('bounds', map);
            if (document.getElementById('originB').value) {
                getdirection();
            }
        } else {
            document.getElementById('originB').readOnly = true;
            document.getElementById('originA').readOnly = false;
            var inputA = (document.getElementById('originA'));
            var autocompleteA = new google.maps.places.Autocomplete(inputA);
            autocompleteA.bindTo('bounds', map);
            if (document.getElementById('originA').value) {
                getdirection();
            }
        }
    }
    
    if (!document.getElementById('originA').readOnly) {
        var inputA = (document.getElementById('originA'));
        var autocompleteA = new google.maps.places.Autocomplete(inputA);
        autocompleteA.bindTo('bounds', map);
    }
    if (!document.getElementById('originB').readOnly) {
        var inputB = (document.getElementById('originB'));
        var autocompleteB = new google.maps.places.Autocomplete(inputB);
        autocompleteB.bindTo('bounds', map);
    }


    var directionsDisplay;
    var directionsService = new google.maps.DirectionsService();
    directionsDisplay = new google.maps.DirectionsRenderer();

    function calcRoute(start, end) {
        if ($('input[name="travelMode"]:checked').val() == 'DRIVING') {
            var request = {
                origin: new google.maps.LatLng(parseFloat(start[0]), parseFloat(start[1])),
                destination: new google.maps.LatLng(parseFloat(end[0]), parseFloat(end[1])),
                travelMode: google.maps.TravelMode.DRIVING
            };
        }
        if ($('input[name="travelMode"]:checked').val() == 'TRANSIT') {
            var request = {
                origin: new google.maps.LatLng(parseFloat(start[0]), parseFloat(start[1])),
                destination: new google.maps.LatLng(parseFloat(end[0]), parseFloat(end[1])),
                travelMode: google.maps.TravelMode.TRANSIT
            };
        }
        if ($('input[name="travelMode"]:checked').val() == 'WALKING') {
            var request = {
                origin: new google.maps.LatLng(parseFloat(start[0]), parseFloat(start[1])),
                destination: new google.maps.LatLng(parseFloat(end[0]), parseFloat(end[1])),
                travelMode: google.maps.TravelMode.WALKING
            };
        }
        /*
         if($('input[name="travelMode"]:checked').val()=='BICYCLING'){
         var request = {
         origin:  new google.maps.LatLng(parseFloat(start[0]), parseFloat(start[1])),
         destination: new google.maps.LatLng(parseFloat(end[0]), parseFloat(end[1])),
         travelMode: google.maps.TravelMode.BICYCLING
         };
         }
         */
        directionsService.route(request, function(response, status) {
            if (status == google.maps.DirectionsStatus.OK) {
                document.getElementById('directions-panel').innerHTML = '';
                directionsDisplay.setDirections(response);
                directionsDisplay.setMap(map);
                directionsDisplay.setPanel(document.getElementById('directions-panel'));
            } else {
                document.getElementById('directions-panel').innerHTML = '<p style="margin-top:5px" class="note-msg"><?php echo $this->__('Could not find a route between A and B.'); ?></p>';
            }
        });
    }

    function getdirection() {
        var endvalue = new Array();
        var end = new Array();
        var start = new Array();
        if (!document.getElementById('originA').readOnly) {
            var start = new Array(<?php echo $store->getLatitude() ?>,<?php echo $store->getLongtitude() ?>);
            var geocoder = new google.maps.Geocoder();
            var address = document.getElementById("originA").value;
            geocoder.geocode({'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK)
                {
                    endvalue = results[0].geometry.location;
                    end[0] = endvalue.k;
                    end[1] = endvalue.A;
                    calcRoute(start, end);
                }
            });
        }
        if (!document.getElementById('originB').readOnly) {
            end[0] = <?php echo $store->getLatitude() ?>;
            end[1] = <?php echo $store->getLongtitude() ?>;
            var geocoder = new google.maps.Geocoder();
            var address = document.getElementById("originB").value;
            geocoder.geocode({'address': address}, function(results, status) {
                if (status == google.maps.GeocoderStatus.OK)
                {
                    endvalue = results[0].geometry.location;
                    start[0] = endvalue.k;
                    start[1] = endvalue.A;
                    calcRoute(start, end);
                }
            });
        }
    }

    function changeImage(element) {
        var url_big_image = document.getElementById('image').src;
        document.getElementById('image').src = element.src;
        element.src = url_big_image;
    }
    function printstore() {
        infoWindow.close();
        window.print();
    }
      var addressValue =  document.getElementById("address").value;
        disiableRadius(addressValue);
        function disiableRadius(text) {
            if(text.length){
                document.getElementById("radius").disabled  = false;
                  <?php if(!isset($_POST['radius'])): ?>
                    document.getElementById("radius").value  = '<?php echo $deaultRadius; ?>';
                 <?php endif; ?>
            }else{
                document.getElementById("radius").value  = '';
                document.getElementById("radius").disabled  = true;
            }
        }
        
       window.onload = function() {
            if(!document.getElementById("country")){
                 document.getElementById("countryh").innerHTML='<input type="hidden" value="" name="country" id="country"/>';
            }
             var  autocompleteBilling = new google.maps.places.Autocomplete(document.getElementById('address'), {types: ['geocode']});
            google.maps.event.addListener(autocompleteBilling, 'place_changed', function() {
                 var place = autocompleteBilling.getPlace();
                 
                 for (var i = 0; i < place.address_components.length; i++) {
                    if(place.address_components[i].types[0] == 'country'){
                        document.getElementById("country").value=place.address_components[i]['short_name'];
                    }
                }
            });
        };
</script>
<style>
    
    #radius:disabled { background: #cdcdcd; }
</style>

